var vue = new Vue({
	
	el : '#company_div',
	data : {
		tableData : [],
		loading: false,
		company : {
			companyCode : '',
			companyName : '',
			companyDesc : '',
			companyAddress : '',
			companyEamil : '',
			companyPhone : ''
		},
		rules : {
			companyName :{
				required : true,min:2,max:8,trigger : 'blur',message : '公司名称需要输入，2~8字符之间'
			},
			companyEamil : {
				required : true,max:20,trigger:'blur',message:'邮箱需要输入，不然无法正常使用contract功能'
			},
			companyPhone : {
				required : true,max:11,trigger:'blur',type:'number',message:'手机号请输入，客户更快找到你'
			}
		}
	},
	mounted(){
		this.queryCompany();
	},
	methods : {
		fullForm(row){
			this.company = row;
		},
		queryCompany(){
			
			$.ajax({
				url : COMMON_URL.URL+'customerCompany/getCompanyDetail',
				dataType : 'json',
				type : 'get',
				success : function(data){
					if(data.ok){
						vue.tableData = data.data;
					}else{
						swal(data.msg,'','warning');
					}
				},
				error : function(data){
					swal('服务器故障','','error');
				}
			});
			
		},
		closePopper(){
			$('#company_controller_btn').trigger("click");
		},
		updateForm(id,row){
			this.$refs[id].validate((valid)=>{
				if(valid){
					$.ajax({
						url : COMMON_URL.URL+'customerCompany/updateCompanyDetail',
						dataType : 'json',
						type : 'post',
						contentType : 'application/json',
						data : JSON.stringify(vue.company),
						success : function(data){
							if(data.ok){
								vue.closePopper();
							}else{
								vue.$message({
									showClose:true,
									type:'warning',
									message:data.msg
								});
							}
						}
					});
				}else{
					return false;
				}
			});
		}
	}
	
	
});